
INPUT_FOLDER="data2"
OUTPUT_FOLDER="3dmm"
find "$INPUT_FOLDER" -maxdepth 1 -type f -regex '.*\.\(avi\|mkv\|mp4\|wmv\|flv\|mov\)$' -print0 | while IFS= read -r -d $'\0' file; do

  FILENAME=$(basename "$file")
  FILENAME_WITHOUT_EXT="${FILENAME%.*}"
  SUFFIX="${FILENAME#*.}"
  CROPPED_FILE="${FILENAME_WITHOUT_EXT}_cropped.${SUFFIX}"
  OUTPUT_FILE="${OUTPUT_FOLDER}/${FILENAME_WITHOUT_EXT}_cropped.npz"

  if [[ "$FILENAME" == *"_cropped"* ]]; then
    continue  
  fi
  
  # 不存在cropped文件则进行剪切
  if [ ! -f "$INPUT_FOLDER/$CROPPED_FILE" ]; then
    python flame2gs/crop_extract.py --root_folder $INPUT_FOLDER --video_name $FILENAME
  fi
  
  # 不存在跟踪结果则进行跟踪
  if [ ! -f $OUTPUT_FILE ]; then
    python flame2gs/track_3dmm.py --root_folder $INPUT_FOLDER --video_name $CROPPED_FILE --out-folder $OUTPUT_FOLDER
  fi

  done